import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/batteryinfo',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      name: 'Batteryinfo',
      component: () => import('@/views/batteryInfo/index')
      // meta: { title: 'route.home', icon: 'el-icon-s-home' }
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: 'route.home', icon: 'el-icon-s-home' }
    }]
  },
  // 换电柜
  {
    path: '/battery',
    component: Layout,
    children: [{
      path: '',
      name: 'Battery',
      component: () => import('@/views/battery/index'),
      meta: { title: 'route.electric', icon: 'element-icons el-icon-peidianxiang-copy' }
    }
    ]
  },
  // 代理商
  {
    path: '/merchant',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Member',
        component: () => import('@/views/merchant/member'),
        meta: { title: 'route.merchant', icon: 'element-icons el-icon-jingxiaoshang' }
      }
    ]
  },
  {
    path: '/investment',
    component: Layout,
    children: [
      {
        path: '',
        name: 'investment',
        component: () => import('@/views/merchant/member'),
        meta: { title: 'route.investment', icon: 'element-icons el-icon-peidianxiang-copy' }
      }
    ]
  },
  {
    path: '/member',
    component: Layout,
    children: [
      {
        path: '',
        name: 'member',
        component: () => import('@/views/merchant/member'),
        meta: { title: 'route.member', icon: 'element-icons el-icon-peidianxiang-copy' }
      }
    ]
  },
  {
    path: '/report',
    component: Layout,
    children: [
      {
        path: '',
        name: 'report',
        component: () => import('@/views/merchant/member'),
        meta: { title: 'route.report', icon: 'element-icons el-icon-peidianxiang-copy' }
      }
    ]
  },
  {
    path: '/commodity',
    component: Layout,
    children: [
      {
        path: '',
        name: 'commodity',
        component: () => import('@/views/merchant/member'),
        meta: { title: 'route.commodity', icon: 'element-icons el-icon-peidianxiang-copy' }
      }
    ]
  }
  // {
  //   path: '/investment',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'member',
  //       name: 'Member',
  //       component: () => import('@/views/merchant/member'),
  //       meta: { title: 'route.merchant', icon: 'merchant' }
  //     }
  //   ]
  // },
  // {
  //   path: '/commodity',
  //   component: Layout,
  //   redirect: '/commodity/index',
  //   meta: { title: 'route.commodity', icon: 'el-icon-s-grid' },
  //   children: [{
  //     path: 'index',
  //     name: 'Commodity',
  //     component: () => import('@/views/commodity/index'),
  //     meta: { title: 'route.commodityCenter', icon: 'merchant' }
  //   },
  //   {
  //     path: 'order',
  //     name: 'Order',
  //     component: () => import('@/views/commodity/order'),
  //     meta: { title: 'route.order', icon: 'merchant' }
  //   }
  //   ]
  // },
  // {
  //   path: '/platform',
  //   component: Layout,
  //   redirect: '/platform/marketing',
  //   meta: { title: 'route.platform', icon: 'el-icon-s-platform' },
  //   children: [{
  //     path: 'marketing',
  //     name: 'Marketing',
  //     component: () => import('@/views/platform/marketing'),
  //     meta: { title: 'route.marketing', icon: 'merchant' }
  //   },
  //   {
  //     path: 'cms',
  //     name: 'CMS',
  //     component: () => import('@/views/platform/cms'),
  //     meta: { title: 'route.cms', icon: 'merchant' }
  //   }
  //   ]
  // },
  // {

  //   path: '/finance',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     name: 'Finance',
  //     component: () => import('@/views/finance/index'),
  //     meta: { title: 'route.finance', icon: 'element-icons el-icon-guoyouqiyecaiwu' }
  //   }]
  // },

  // {
  //   path: '/settings',
  //   component: Layout,
  //   redirect: '/settings/disposition',
  //   meta: { title: 'route.sandp', icon: 'el-icon-s-tools' },
  //   children: [{
  //     path: 'disposition',
  //     name: 'Disposition',
  //     component: () => import('@/views/settings/disposition'),
  //     meta: { title: 'route.settings', icon: 'merchant' }
  //   },
  //   {
  //     path: 'authority',
  //     name: 'Authority',
  //     component: () => import('@/views/settings/authority'),
  //     meta: { title: 'route.permissions', icon: 'merchant' }
  //   }

  //   ]
  // }

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     }
  //     // {
  //     //   path: 'tree',
  //     //   name: 'Tree',
  //     //   component: () => import('@/views/tree/index'),
  //     //   meta: { title: 'Tree', icon: 'tree' }
  //     // }
  //   ]
  // }

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
